<?php
require_once "utils/Constants.php";
require_once "UsersManager.php";

class EntryPointsManager extends REST {
	
	private function generateEntryPoints() {
		// Entry Points Array
		$entryPoints = array();
		// Courses Service URL
		$entryPoints[EntryPointsKeys::COURSES_SERVICE] =  PROTOCOL.$_SERVER['SERVER_NAME'].EntryPoints::API.EntryPoints::COURSES;
		// Rooms Service URL
		$entryPoints[EntryPointsKeys::ROOMS_SERVICE] = PROTOCOL.$_SERVER['SERVER_NAME'].EntryPoints::API.EntryPoints::ROOMS;
		// Bookings Service URL
		$entryPoints[EntryPointsKeys::BOOKINGS_SERVICE] = PROTOCOL.$_SERVER['SERVER_NAME'].EntryPoints::API.EntryPoints::BOOKINGS;
		// Notifications Service URL
		$entryPoints[EntryPointsKeys::NOTIFICATIONS_SERVICE] = PROTOCOL.$_SERVER['SERVER_NAME'].EntryPoints::API.EntryPoints::NOTIFICATIONS;
		// User Service URL
		$entryPoints[EntryPointsKeys::USER_SERVICE] = PROTOCOL.$_SERVER['SERVER_NAME'].EntryPoints::API.EntryPoints::USERS;
		
		// Send The Array 
		$this->response($this->toJSON($entryPoints), StatusCodes::STATUS_CODE_SUCCESS);	
		
		
	}
	
	public function processApi(){
		// Language
		$headers =  apache_request_headers();
		if (isset($headers['Accept-Language'])) {
			$language = $headers['Accept-Language'];
			if ($language == "ro") {
				require_once "utils/Localized_RO.php";		
			} else {
				require_once "utils/Localized_EN.php";		
			}
		} else {
			require_once "utils/Localized_EN.php";	
		}
		// Check authorization token
		$userManager = new UsersManager();
		$userInfo = $userManager->getUserInfoForAuthorization();
		
		$METHOD = $this->get_request_method();
		if ($METHOD == "GET") {
			$this->generateEntryPoints();	
		} else {
			// HTTP Method Not Supported
			$jsonResults[MESSAGE] = Strings::HTTP_METHOD_NOT_SUPPORTED;
			$this->response($this->toJSON($jsonResults), StatusCodes::STATUS_CODE_BAD_REQUEST);	
		}
	}
}